/*
 自定义线程终止
 */
public class ThreadExit {
    public static void main(String[] args) throws InterruptedException {
        T t1 = new T();
        t1.start();
        System.out.println("休眠 10s 中......");
        Thread.sleep(10 * 1000);
        t1.setLoop(false);
    }
}

class T extends Thread{
    private boolean loop = true;

    public void setLoop(boolean loop) {
        this.loop = loop;
    }
    int count = 0;
    @Override
    public void run(){
        while(loop){
            System.out.println("T is running~~" + (count++));
            try {
                sleep(60);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }
}
